package com.app.OOS.service;


import java.util.List;

import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.app.OOS.domain.Batch;
import com.app.OOS.domain.Batch_courseware;
import com.app.OOS.domain.Course;
import com.app.OOS.domain.Course_Courseware;
import com.app.OOS.domain.Courseware;
import com.app.OOS.domain.Record;
import com.app.OOS.domain.Score;
import com.app.OOS.domain.User;
import com.app.OOS.domain.User_batch;
import com.app.OOS.domain.User_courseware_batch;
import com.app.OOS.mapper.AdminMapper;

@Service
public class AdminService {
	@Autowired
	AdminMapper adminMapper;
	//审核学员
	public List<User> selectUsers(int tmp,int limit){
		return adminMapper.selectUsers(tmp,limit);
	}
	public int tol() {
		int tol = adminMapper.tol();
		return tol;
	}
	//通过学员
	public void updateUsers(int userId) {
		adminMapper.updateUsers(userId);
	}
	
	//不通过学员
	public void deleteUsers(int userId) {
		adminMapper.deleteUsers(userId);
	}
	
	//课程管理 带参数
	public List<Course> selectCourse(int tmp,int limit){
		List<Course> list = adminMapper.selectCourse(tmp,limit);
		return  list;
	}
	public int tol2() {
		int tol = adminMapper.tol2();
		return tol;
	}
	
	//课程管理 不带参数
	public List<Course> selectCourses(){
		List<Course> list = adminMapper.selectCourses();
		return  list;
		}
	//删除课程
	public void deleteCourse(int courseId) {
		adminMapper.deleteCourse(courseId);
	}
	
	//查询course课程表字段 （集合）
	public List<Integer> selectCourseId() {
		List<Course> list = adminMapper.selectCourses();
		List<Integer> courseId =list.stream().map(Course->Course.getCourseId()).collect(Collectors.toList());
		return courseId;
	}
	
	public List<String> selectCourseName() {
		List<Course> list = adminMapper.selectCourses();
		List<String> courseName =list.stream().map(Course->Course.getCourseName()).collect(Collectors.toList());
		return courseName;
		}
	
	//更新课程
	public String updateCourse(String courseName,int courseId) {
		List<Course> list = adminMapper.selectCourses();
		List<String> courseName2 =list.stream().map(Course->Course.getCourseName()).collect(Collectors.toList());
		System.out.println(courseName2);
		System.out.println(courseName2.size());
		System.out.println(courseName);
		String msg=null;
		if(courseName2.contains(courseName)==false) {
		 adminMapper.updateCourse(courseName, courseId);
		 	msg="修改成功";
		}else {
			msg="含有相同课程名";
		}
		return msg;	
	}
	
	//新增课程
	public String insertCourse(int courseId,String courseName) {
		List<Course> list = adminMapper.selectCourses();
		List<String> courseName2 =list.stream().map(Course->Course.getCourseName()).collect(Collectors.toList());
		List<Integer> courseId2 =list.stream().map(Course->Course.getCourseId()).collect(Collectors.toList());
		String msg=null;
		if(courseName2.contains(courseName)==true||courseId2.contains(courseId)) {
			msg="no";
		}else {
			adminMapper.insertCourse(courseId, courseName);
			msg="ok";
		}
		return msg;
	}
	
	//批次查询
	public List<Batch> selectBatch(int tmp,int limit) {
		List<Batch> list = adminMapper.selectBatch(tmp, limit);
		return list;
	}
	public List<Batch> selectBatchs() {
		List<Batch> list = adminMapper.selectBatchs();
		return list;
	}
	public int tol3() {
		int tol = adminMapper.tol3();
		return tol;
	}
	
	
	//删除批次
	public void  deleteBatch(int batchId) {
		adminMapper.deleteBatch(batchId);
	}
	
	
	//更新批次
	public String updateBatch(String batchName,int batchId) {
		List<Batch> list = adminMapper.selectBatchs();
		List<String> batchName2 =list.stream().map(Batch->Batch.getBatchName()).collect(Collectors.toList());
		System.out.println(batchName2);
		System.out.println(batchName2.size());
		System.out.println(batchName);
		String msg=null;
		if(batchName2.contains(batchName)==false) {
			adminMapper.updateBatch(batchName, batchId);
			 msg="修改成功";
		}else {
			msg="含有相同课程名";
		}
		return msg;	
	}
		
	//新增批次
	public String insertBatch(int batchId,String batchName) {
		List<Batch> list = adminMapper.selectBatchs();
		List<String> batchName2 =list.stream().map(Batch->Batch.getBatchName()).collect(Collectors.toList());
		List<Integer> batchId2 =list.stream().map(Batch->Batch.getBatchId()).collect(Collectors.toList());
		String msg=null;
		if(batchName2.contains(batchName)==true||batchId2.contains(batchId)) {
			msg="no";
		}else {
			adminMapper.insertBatch(batchId, batchName);
			msg="ok";
		}
		return msg;
	}
			
	//查询课件信息
	public List<Course_Courseware> selectCourseWare(int tmp,int limit){
		List<Course_Courseware> list = adminMapper.selectCourseWare(tmp, limit);
		return list;
	}
	
	public List<Courseware> selectCourseWares(){
		List<Courseware> list = adminMapper.selectCourseWares();
		return list;
	}
	public int tol4() {
		int tol = adminMapper.tol4();
		return tol;
	}
	
	//删除课件
	public void deleteCourseWare(int coursewareId) {
		adminMapper.deleteCourseWare(coursewareId);
	}
	
	//修改课件
	public void updateCourseWare(String coursewareName,int courseId,int coursewareId) {
		adminMapper.updateCourseWare(coursewareName, courseId,coursewareId);
	}
	
	//增加课件
	public void insertCourseWare(int coursewareId,String coursewareName,int courseId,int cwPeriod,String src) {
		
		
			adminMapper.insertCourseware(coursewareId, coursewareName, courseId,cwPeriod,src);
	}
	
	//查询 批次-课件
	public List<Batch_courseware> selectBatchCourseWare(int tmp,int limit){
		List<Batch_courseware> list = adminMapper.selectBatchCourseWare(tmp, limit);
		return list;
	}
	public int tol5() {
		int tol = adminMapper.tol5();
		return tol;
	}
	
	
	//删除批次-课件
	public void deleteBatchCourseWare(int batch_courseware_id) {
		adminMapper.deleteBatchCourseWare(batch_courseware_id);
	}
	
	//修改批次-课件
	public String updateBatchCourseWare(int batchId,int coursewareId,int batch_courseware_id) {
		int tol = adminMapper.selectBatchCourseWares(batchId, coursewareId);
		String msg = null;
		if(tol>=1) {
		 msg="no";
		}else {
		 adminMapper.updateBatchCourseWare(batchId, coursewareId, batch_courseware_id);
		 msg="yes";
		}
		return msg;
		}
	
	public String insertBatchCourseWare(int batchId,int coursewareId,int batch_courseware_id) {
		int tol = adminMapper.selectBatchCourseWares(batchId, coursewareId);
		int t= adminMapper.selectBatchCourseWaress(batch_courseware_id);
		String msg = null;
		if(tol>=1 || t>=1) {
		 msg="no";
		}else {
		 adminMapper.insertBatchCourseWare(batchId, coursewareId, batch_courseware_id);
		 msg="yes";
		}
		return msg;
		}
	
	//查询学员-批次
	public List<User_batch> selectUserBatch(int tmp,int limit){
		List<User_batch> list = adminMapper.selectUserBatch(tmp, limit);
		return list;
	}
	public int tol6() {
		int tol = adminMapper.tol6();
		return tol;
	}
	
	
	//删除 学员-批次
	public void deleteUserBatch(int user_batch_id) {
		adminMapper.deleteUserBatch(user_batch_id);
	}
	
	//查询学员  不带参数
	public List<User> selectUseres(){
		List<User> list= adminMapper.selectUseres();
		return list;
	}
	
	//更新 学员-批次
	public void updateUserBatch(int user_batch_id,int batchId) {
		adminMapper.updateUserBatch(user_batch_id,batchId);
	}
	
	//查询是否有相同的数据
	public String insertUserBatch(int user_batch_id,int userId,int batchId) {
		int tol=adminMapper.selectUserBatchSS(userId,batchId);
		int t=adminMapper.SelectA(user_batch_id);
		String msg=null;
		if(tol>=1 || t>=1) {
			msg="no";
		}else {
			adminMapper.insertUserBatch(user_batch_id, userId, batchId);
			msg="yes";
		}
		return msg;
	}
	
	//查询学生成绩
	public List<Score> selectScore(int tmp,int limit){
		List<Score> list = adminMapper.selectScore(tmp, limit);
		return list;
	}
	public int tol7() {
		return adminMapper.tol7();
	}
	
	//更新时间
	public void updateCtime(int Ctime,int coursewareId) {
		adminMapper.updateCtime(Ctime, coursewareId);
	}
	
	//查询记录
	public List<User_courseware_batch> seclctRR() {
		List<User_courseware_batch>list=adminMapper.selectRR();
		return list;
	}
}

